import { ref, computed } from "vue";
import * as THREE from "three";
import * as TWEEN from "@tweenjs/tween.js";
import { defineStore } from "pinia";
import {
  Product3DGroup,
  AssemblyProductGroup,
  Sub3DGroup,
  Base3DGroup,
} from "@/core3d/types/DrawingGroups/groups";
import type { KujialeAuditOrder } from "@/core3d/types/KujialeJsonModels/KujialeAuditOrder";
import type { KujialePartnerOrder } from "@/core3d/types/KujialeJsonModels/KujialePartnerOrder";
import type { LogItem } from "@/core3d/types/Log/LogItem";

export const useCurrentModelStore = defineStore("currentmodel", () => {
  const currentAuditOrder = ref<KujialeAuditOrder>();
  const setCurrentAuditOrder = (v: KujialeAuditOrder) => {
    currentAuditOrder.value = v;
  };

  const currentCurrentModelData = ref<Base3DGroup[]>();
  const setCurrentModel = (groups: Base3DGroup[]) => {
    currentCurrentModelData.value = groups;
  };

  const currentPartnerOrder = ref<KujialePartnerOrder>();
  const setCurrentPartnerOrder = (v: KujialePartnerOrder) => {
    currentPartnerOrder.value = v;
  };

  const currentCreateDate = ref<Date>();
  const setCurrentCreateDate = (d: number) => {
    currentCreateDate.value = new Date(d);
  };

  const currentRightTabNameTick = ref(0);
  const currentRightTabName = ref("order");
  const setCurrentRightTabName = (s: string) => {
    currentRightTabName.value = s;
    currentRightTabNameTick.value += 1;
  };

  const currentTWEENGRoup = ref<TWEEN.Group>();
  const setThreeEnv = (tweengroup: TWEEN.Group) => {
    currentTWEENGRoup.value = tweengroup;
  };

  const currentLogs = ref<LogItem[]>();
  const setLogs = (logs: LogItem[]) => {
    currentLogs.value = logs;
  };

  return {
    currentCurrentModelData,
    setCurrentModel,
    currentAuditOrder,
    setCurrentAuditOrder,
    currentPartnerOrder,
    setCurrentPartnerOrder,
    currentCreateDate,
    setCurrentCreateDate,
    currentRightTabName,
    currentRightTabNameTick,
    setCurrentRightTabName,
    currentTWEENGRoup,
    setThreeEnv,
    currentLogs,
    setLogs,
  };
});
